<?php
// curl

//phpinfo();
// 初始化curl
//$curl = curl_init();
//
////var_dump($curl); // resource(2) of type (curl)  返回一个curl资源
//// 设置请求地址
//curl_setopt($curl , CURLOPT_URL , 'http://www.1808yysh.com/index.php/admin/ad/index.html');
//
//// 设置请求方式为post
//curl_setopt($curl , CURLOPT_POST , true);
//
//// 发送请求数据
//$data = ['username' => 'jack' , 'password'=> '123456'];
////
////session_start();
////$_SESSION['name'] = $data['username'];
//
//curl_setopt($curl , CURLOPT_POSTFIELDS , $data);
//
//// 设置curl是否直接输出还是返回数据
//curl_setopt($curl , CURLOPT_RETURNTRANSFER , 1);
//// 执行curl
//$content =curl_exec($curl);
//
//curl_close($curl);
//
//
//var_dump($content);


/**
 * @functionName  curl 模拟请求
 * @param $url String  请求地址
 * @param $data Array post请求的数据
 */
function curl ($url , $data=null)
{
    $curl = curl_init();
    curl_setopt($curl , CURLOPT_URL , $url);

    if (!is_null($data)) {
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }

    curl_setopt($curl , CURLOPT_RETURNTRANSFER , 1);
    $content =curl_exec($curl);
    curl_close($curl);
    return $content;
}

//echo curl('http://www.baidu.com' , ['']);





